package com.semidata.trp.business.main;

import com.semidata.rtd.core.http.server.HttpService;
import com.semidata.rtd.core.log.DefaultLogService;
import com.semidata.rtd.core.log.Logger;
import com.semidata.rtd.core.service.ServiceManager;
import com.semidata.trp.business.config.Config;
import com.semidata.trp.business.data.BusinessDataDebugService;
import com.semidata.trp.business.data.DataService;
import com.semidata.trp.business.http.BusinessHttpDispatcher;
import com.semidata.trp.business.report.ReportService;
import com.semidata.trp.business.report.SyncReportService;

public class Main {

    public static void main(String[] args) {
        try {
            Config.init(args.length > 0 ? args[0] : null);
        } catch (Exception e) {
            System.err.println("can not init config");
            e.printStackTrace(System.err);
            System.exit(-1);
        }

        Config config = Config.getConfig();
        ServiceManager.register(new DefaultLogService(config.getLogRoot(), config.isLogDebugEnabled()));
        ServiceManager.register(new BusinessDataDebugService());
        ServiceManager.register(new ReportService());
        ServiceManager.register(new DataService());
        ServiceManager.register(new SyncReportService());
        ServiceManager.register(new HttpService(config.getHttpPort(), config.getHttpThreads(), new BusinessHttpDispatcher()));
        ServiceManager.startAll();
        Logger.log("INFO", "business server started");
        ServiceManager.sync();
    }
}
